/*
 * gy_enplisten.h
 *
 *  Created on: 2015年9月15日
 *      Author: gaoyi
 */

#ifndef GY_ENPLISTEN_H_
#define GY_ENPLISTEN_H_

#include "gy_enpdef.h"

class GYEnpListenInfo
{
public:
	GYEnpListenInfo()
    {
    };

public:
	std::string			m_szListenIP;		///< 侦听的IP
	unsigned short		m_unListenPort;		///< 侦听的端口

	unsigned int		m_uiIdeleTimeout;	///< 发呆超时值, 默认为-1, 即不检测发呆, accepte的sock会继承此值

    EEnpPackage	        m_stPackageType;    ///< 数据包的格式

    unsigned char       m_ucEncodeMethod;     ///< 消息体编码方法
    unsigned char       m_ucDecodeMethod;     ///< 消息体解码方法
};

class GYEnpCtrl;
class GYEnpListen : public CTEpollObject<GYEnpCtrl>
{
protected:
	friend class GYEnpCtrl;
protected:
	GYEnpCtrl*		m_pstOwner;
	CTSocket		m_stSocket;
	GYEnpListenInfo		m_stListenInfo;
	unsigned int		m_uiCreateTime;
	unsigned int		m_uiLastTime;
public:
	GYEnpListen():m_stSocket(PF_INET,SOCK_STREAM, false),m_uiCreateTime(0), m_uiLastTime(0)
	{
	}

	virtual ~GYEnpListen()
	{
		 Unregister(); // 先Unregister从epoll注销, 然后再关闭socket
	}

	const GYEnpListenInfo& GetListenInfo() const
	{
		return m_stListenInfo;
	}

	int Init(GYEnpCtrl &stOnwer, const char *pszIPAddr, unsigned short ushPort);
};

#endif
